<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="public/layui/css/layui.css">
    <script type="text/javascript" src="public/layui/layui.js"></script>
    <title>登录</title>
    <style>
        .header {
            background-color: #1e9fff;
            font-size: 12px;
            padding: 10px;
            color: #fff;
        }
    </style>
</head>

<body>

    <div class="header">
        <h1>登录</h1>
        <a href="?p=index" class="layui-font layui-font-12 " style="color: #fff;"><{$sys.base.title}>
        </a>
    </div>
    <form class="layui-form layui-padding-3">
        <div class="demo-login-container">
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-username"></i>
                    </div>
                    <input type="text" name="username" value="" lay-verify="required" placeholder="用户名"
                        lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-password"></i>
                    </div>
                    <input type="password" name="password" value="" lay-verify="required" placeholder="密   码"
                        lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn layui-bg-blue layui-btn-fluid" lay-submit lay-filter="log">登录</button>
            </div>
            <div class="layui-form-item">
                <a href="?p=index&c=register&a=index"
                    class="layui-btn layui-btn-primary layui-border-blue  layui-btn-fluid">注册</a>
            </div>
        </div>
    </form>
    <p style="text-align: center;" class="layui-font-gray layui-font-12">
        <a href="?p=index" class="layui-font-gray layui-font-12"><{$sys.base.copyright}></a>
    </p>
    <script>
        layui.use(
            function () {
                $ = layui.$;
                var layer = layui.layer
                var form = layui.form
                form.on('submit(log)', function (data) {
                    var field = data.field; // 获取表单字段值
                    $.post('?p=index&c=login&a=doLog', field, (res) => {
                        if (res.code == 200) {
                            layer.msg('登录成功')
                            window.location.href = '?p=index&c=index&a=index'
                        } else if (res.code == 203) {
                            layer.msg(res.msg)
                        } else {
                            layer.msg(res.msg)
                        }
                        $('#captcha').attr('src', '?p=index&c=register&a=captcha&m=' + Math.random())
                    }, 'json')
                    return false; // 阻止默认 form 跳转
                });
            })

    </script>
</body>

</html>